﻿using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using Util.Domains;

namespace IterationLife.System.Models {
    /// <summary>
    /// 第三方用户绑定信息
    /// </summary>
    [Description( "第三方用户绑定信息" )]
    public partial class ExternalUserBinding : AggregateRoot<ExternalUserBinding>,IDelete {
        /// <summary>
        /// 初始化第三方用户绑定信息
        /// </summary>
        public ExternalUserBinding() : this( Guid.Empty ) {
        }

        /// <summary>
        /// 初始化第三方用户绑定信息
        /// </summary>
        /// <param name="id">第三方用户绑定信息标识</param>
        public ExternalUserBinding( Guid id ) : base( id ) {
        }

        /// <summary>
        /// 用户编号
        /// </summary>
        [Required(ErrorMessage = "用户编号不能为空")]
        public Guid UserId { get; set; }
        /// <summary>
        /// 第三方用户编号
        /// </summary>
        [Required(ErrorMessage = "第三方用户编号不能为空")]
        [StringLength( 255, ErrorMessage = "第三方用户编号输入过长，不能超过255位" )]
        public string ExternalUserId { get; set; }
        /// <summary>
        /// 第三方编码
        /// </summary>
        [Required(ErrorMessage = "第三方编码不能为空")]
        [StringLength( 100, ErrorMessage = "第三方编码输入过长，不能超过100位" )]
        public string ExternalCode { get; set; }
        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime? CreationTime { get; set; }
        /// <summary>
        /// 是否删除
        /// </summary>
        [Required(ErrorMessage = "是否删除不能为空")]
        public bool IsDeleted { get; set; }
        
        /// <summary>
        /// 用户
        /// </summary>
        public virtual User User { get; set; }
        
        /// <summary>
        /// 添加描述
        /// </summary>
        protected override void AddDescriptions() {
            AddDescription( "第三方用户绑定编号", Id );
            AddDescription( "用户编号", UserId );
            AddDescription( "第三方用户编号", ExternalUserId );
            AddDescription( "第三方编码", ExternalCode );
            AddDescription( "创建时间", CreationTime );
        }
        
        /// <summary>
        /// 添加变更列表
        /// </summary>
        protected override void AddChanges( ExternalUserBinding newEntity ) {
            AddChange( "Id", "第三方用户绑定编号", Id, newEntity.Id );            
            AddChange( "UserId", "用户编号", UserId, newEntity.UserId );
            AddChange( "ExternalUserId", "第三方用户编号", ExternalUserId, newEntity.ExternalUserId );
            AddChange( "ExternalCode", "第三方编码", ExternalCode, newEntity.ExternalCode );
            AddChange( "CreationTime", "创建时间", CreationTime, newEntity.CreationTime );
        }
    }
}